/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						 mini_map_renderer.h

	$Header: /heroes4/mini_map_renderer.h $

	$NoKeywords: $

 ************************************************************************/

#if !defined( MINI_MAP_RENDERER_H_INCLUDED )
#define MINI_MAP_RENDERER_H_INCLUDED

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#pragma warning( disable: 4786 )

#include <set>
#include <vector>

#include "abstract_adventure_map.h"
#include "abstract_bitmap.h"
#include "map_point.h"
#include "owned_ptr.h"
#include "screen_point.h"
#include "shared_ptr.h"
#include "uncopyable.h"

class t_clip_list;

// ------------------------------------------------------------------------------
// Details namespace
// ------------------------------------------------------------------------------

namespace mini_map_renderer_details
{

	class t_internal_map_data;

} // Details namespace

// ------------------------------------------------------------------------------
// t_mini_map_renderer_client class
// ------------------------------------------------------------------------------

class t_mini_map_renderer_client
{
public:
	// Types
	typedef t_shared_ptr< t_abstract_bitmap16 > t_back_buffer_ptr;

	// Member functions
	virtual t_back_buffer_ptr	create_back_buffer( t_screen_point const & size ) = 0;
	virtual void				on_rect_dirtied( t_screen_rect const & dirtied_rect );
	virtual void				on_view_level_changed( int level );
	virtual void				on_view_resized( t_screen_point const & size );

protected:
	// Destructor
	~t_mini_map_renderer_client() {}
};

// ------------------------------------------------------------------------------
// t_mini_map_renderer class
// ------------------------------------------------------------------------------

class t_mini_map_renderer : private t_uncopyable
{
public:
	// Types
	typedef t_mini_map_renderer_client			t_client;
	typedef t_client::t_back_buffer_ptr			t_back_buffer_ptr;
	typedef t_abstract_adventure_map			t_adventure_map;
	typedef t_adventure_map::t_object			t_object;
	typedef t_adventure_map::t_object_id		t_object_id;
	typedef t_adventure_map::t_tile_point_set	t_tile_point_set;

	// Static member functions
	static void	on_adv_object_moved(
					t_adventure_map const &	adventure_map,
					t_object_id				object_id );
	static void	on_adv_object_placed(
					t_adventure_map const &	adventure_map,
					t_object_id				object_id );
	static void	on_moving_adv_object(
					t_adventure_map const &	adventure_map,
					t_object_id				object_id );
	static void	on_removing_adv_object(
					t_adventure_map const &	adventure_map,
					t_object_id				object_id );
	static void	on_terrain_changed(
					t_adventure_map const &		adventure_map,
					int							level,
					t_tile_point_set const &	changed_tile_points );
	static void	on_visibility_changed(
					t_adventure_map const &		adventure_map,
					int							team_num, 
					int							level, 
					t_tile_point_set const &	changed_tile_points );
	static void	refresh( t_adventure_map const & adventure_map );

	// Constructors/Destructor
	t_mini_map_renderer(
		t_client &				client,
		t_adventure_map const &	adventure_map,
		int						team_view );
	virtual ~t_mini_map_renderer();

	// Member functions
	t_adventure_map const &	get_adventure_map() const;
	t_screen_rect			get_tile_rect( t_map_point_2d const & tile_point ) const;
	int						get_view_level() const;
	t_screen_point			get_view_size() const;
	t_screen_rect const &   get_viewport_rect() const;
	t_screen_rect			mini_to_view( t_screen_rect const &	rect ) const;
	t_screen_point			mini_to_view( t_screen_point const & point ) const;
	void					resize( t_screen_point const & new_size );
	void					set_team_view ( int new_team_view );
	void					set_view_level( int new_view_level );
	void					set_viewport_rect( t_screen_rect const & new_viewport_rect );
	void					update( t_screen_rect const & rect );
	t_screen_rect			view_to_mini( t_screen_rect const &	rect ) const;
	t_screen_point			view_to_mini( t_screen_point const & point ) const;
	
protected:
	// Constructor
	t_mini_map_renderer(
		t_adventure_map const &	adventure_map,
		int						team_view );

	// Member functions
	virtual t_back_buffer_ptr	create_back_buffer( t_screen_point const & size );
	virtual void				on_rect_dirtied( t_screen_rect const & dirtied_rect );
	virtual void				on_view_level_changed( int level );
	virtual void				on_view_resized( t_screen_point const & size );
	
private:
	// Types
	class t_impl;
	friend class t_impl;

	friend class mini_map_renderer_details::t_internal_map_data;

	// Data members
	t_owned_ptr< t_impl >	m_impl_ptr;
};

#endif // !defined( MINI_MAP_RENDERER_H_INCLUDED )
